package com.ddy.test.boxiao;

import com.alibaba.fastjson.JSONObject;
import com.ddy.test.inputStream.FileReader;

import java.util.List;
import java.util.Map;

/**
 * Created by ddy on 2017/12/13.
 */
public class ShunyiUserRead {
    public static void main(String[] args) {

        String sy002 = "/Users/ddy/Documents/yun-顺义/sy002-users.txt";
        String sy009 = "/Users/ddy/Documents/yun-顺义/sy009-users.txt";
        //printUsersForExcel(sy002);
        //printUsersForExcel(sy009);
        //printSourceIdSQLForBecUser(sy002);
        //printSourceIdSQLForBecUser(sy009);
        printUniqueNo(sy002);
        printUniqueNo(sy009);

    }




    private static void printUniqueNo(String file) {
        String txt = FileReader.readStringFromTxt(file);
        JSONObject object = JSONObject.parseObject(txt);
        List list = (List) object.get("Data");
        for(Object obj : list){
            Map map = (Map) obj;
            String user = "update sys_user set uniqueNo='" + map.get("Card") + "',source_id='" + map.get("Id") + "' where username='" + map.get("LoginName") + "';";
            System.out.println(user);
        }
    }
    private static void printSourceIdSQLForBecUser(String file) {
        String txt = FileReader.readStringFromTxt(file);
        JSONObject object = JSONObject.parseObject(txt);
        List list = (List) object.get("Data");
        for(Object obj : list){
            Map map = (Map) obj;
            String user = "update sys_user set source_id='" + map.get("Id") + "' where uniqueNo='" + map.get("Card") + "';";
            System.out.println(user);
        }
    }

    public static void printUsersForExcel(String file){
        String txt = FileReader.readStringFromTxt(file);
        JSONObject object = JSONObject.parseObject(txt);
        List list = (List) object.get("Data");
        for(Object obj : list){
            Map map = (Map) obj;
            String user = map.get("RealName") + "\t" + map.get("Card") + "\t" + map.get("LoginName");
            System.out.println(user);
        }
    }

}
